#include "mainwindow.h"
// #include "userinterfaceZZL.h"

#include "qquserinterface.h"
#include "wxuserinterface.h"

// #include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    // , ui(new Ui::MainWindow)
{
    QWidget *centralWidget = new QWidget(this);  // 创建一个 QWidget 作为 central widget
    setCentralWidget(centralWidget);  // 设置 central widget

    this->qqButton = new QPushButton("QQ", this);
    this->wxButton = new QPushButton("微信", this);
    this->titleLabel = new QLabel("请选择要登录的服务", this);

    connect(qqButton, SIGNAL(clicked()), this, SLOT(onQQButtonClicked()));
    connect(wxButton, SIGNAL(clicked()), this, SLOT(onWXButtonClicked()));

    initLayout();
    // ->setupUi(this);
}

MainWindow::~MainWindow()
{
    // delete ui;
}

void MainWindow::initLayout() {
    QVBoxLayout * mainLayout = new QVBoxLayout;
    mainLayout->addWidget(this->titleLabel);
    mainLayout->addWidget(this->qqButton);
    mainLayout->addWidget(this->wxButton);

    centralWidget()->setLayout(mainLayout);
}

void MainWindow::onQQButtonClicked() {
    qDebug() << "qq登录系统启动";
    this->close();
    logininterface * ld = new logininterface("QQ 登录系统", nullptr);
    ld->show();
    if (ld->exec() == QDialog::Accepted) {
        QString username = ld->getReturnStr();
        qDebug() << "qq登录成功";
        qquserinterface* ld2 = new qquserinterface(username, nullptr);
        ld2->show();
    }
}
void MainWindow::onWXButtonClicked() {
    qDebug() << "wx登录系统启动";
    this->close();
    logininterface * ld = new logininterface("微信 登录系统", nullptr);
    ld->show();
    if (ld->exec() == QDialog::Accepted) {
        qDebug() << "wx登录成功";
        QString username = ld->getReturnStr();
        wxuserinterface* ld2 = new wxuserinterface(username, nullptr);
        ld2->show();
    }
}
